<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="itcast" uri="http://itcast.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>留言管理</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Modern Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
 <!-- Bootstrap Core CSS -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.css">
<!-- Custom CSS -->
<link href="${pageContext.request.contextPath }/css/style1.css" rel='stylesheet' type='text/css' />
<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css"> 
<!-- jQuery -->
<script src="${pageContext.request.contextPath }/js/jquery-1.11.0.js"></script>

<!---//webfonts--->  
<!-- Bootstrap Core JavaScript -->
<script src="${pageContext.request.contextPath }/js/bootstrap.js"></script>
    <script>
    	 /*全选或全不选*/
			//1.页面加载
			$(function(){
				//2.获取下面的复选框并将其选中状态设置跟编码的前端复选框保持一致
				$("#select").click(function(){
					 //atrr方法与JQ的版本有关，在1.8.3以下有关
					//$("tbody input[class='selectOne']").attr("checked",this.checked);
					$("tbody input[class='selectOne']").prop("checked",this.checked);
					
				});
			});
			/*全选删除*/
			function jjj(){
				var pList = "";
	            $("[name='all']").each(function () {
	                if ($(this).is(':checked')) {
	                    pList += $(this).val() + ",";
	                }
	            });
	            //去除最后的，
	           pList=pList.substr(0,pList.length-1);
	           var ids = pList;
	           if(pList==""){
	           	alert("请选择");
	           }else{
	        	   var yes = confirm("您确定要删除吗?");
	        	   if(yes){
	        		   $.post(
	   	           			"<%=basePath%>adminMessage/delAllMessage",
	   	           			{"ids":ids},
	   	           			function (data) {
	   							alert("删除成功!");
	   							location.href="<%=basePath%>adminMessage/lsotMessage";
	   						}
	   	           	); 
	        	   }
	           	
	           }

			}
			
		</script>

</head>
<body>
<div id="wrapper">
     <!-- Navigation -->
        <jsp:include page="/WEB-INF/jsp/admin/common.jsp"></jsp:include>
        
        
        <div id="page-wrapper">
           <div class="row" style="background-color: wheat;">
           
              <div class="col-lg-8 navbar-left" style="padding-top: 15px;margin-left:10px;">
               <form class="form-inline" id="" action="${pageContext.request.contextPath }/adminMessage/lsotMessage" method="post">
               	     
					  <div class="form-group">
					    <label for="lldate1">日期：</label>
					    <input type="date" class="form-control" id="lldate1" name="lldate" value="${lldate }" placeholder="日期...">
					  </div>
					  
					   
					     
					  <button type="submit" class="btn btn-default">搜索</button>
					</form>
             </div>
              <!-- <div class="col-lg-2 navbar-right" style="padding-top: 5px;">
									
								<button class="btn btn-info btn-sm glyphicon glyphicon-plus" data-toggle="modal" data-target="#myModal2">
								添加
								</button>
								
					</div> -->
           </div>
        <div class="row">
        <div class="col-md-12">  
  	       <h3>留言管理</h3>
  	        <div class="bs-example4" data-example-id="contextual-table">
              <table class="table table-hover">
              	<!--全选/全不选-->
	             <caption><input type="checkbox" id="select">
	             	
	             	<a href="#" class="btn btn-danger btn-sm" onclick="jjj()">
									<span class="glyphicon glyphicon-trash"></span> 批量删除
								</a>
	             </input>
	             </caption>
					<thead>
						<tr>
							<th>序号</th>
							<th>留言人</th>
							<th>动物名</th>
							<th>日期</th>
							<th>禁言</th>
							
							<th>操作</th>
							
						</tr>
					</thead>
						<tbody>
						<c:forEach items="${page.rows}" var="row" varStatus="vs">
							<tr>
								<td><input type="checkbox" class="selectOne" value="${row.id }" name="all"/><span id="" style="padding-left: 5px;">${vs.count}</span></td>
								<td>${row.founder}</td>
								<td>${row.pname }</td>
								<td>${row.ldate}</td>
								<c:if test="${row.isshow==1 }">
									<td>否</td>
								</a>
								</c:if>
								<c:if test="${row.isshow==2 }">
									<td>是</td>
								</a>
								</c:if>
								
								<td>
								<!--编辑-->
								<c:if test="${row.isshow==1 }">
								<a href="javascript:void(0);" onclick="showMessage(${row.id })">
									
									<button class="btn btn-info btn-sm glyphicon glyphicon-edit" data-toggle="modal" data-target="#myModal">
											详情
											</button>
								</a>
								</c:if>
								<c:if test="${row.isshow==2 }">
									<button class="btn btn-info btn-sm glyphicon glyphicon-edit" onclick="cancelsay(${row.id })">
											取消禁言
											</button>
								</c:if>
								&nbsp;&nbsp;
								<!--删除-->							
								<a href="javascript:void(0);" onclick="deleteMessage(${row.id })" class="btn btn-danger btn-sm">
									<span class="glyphicon glyphicon-trash"></span> 删除
								</a>
								
							</td>	
							
							</tr>
						</c:forEach>	
					</tbody>
				</table>
				<div class="col-md-12 text-right">
							<span>共<font style="color: red;">${total}</font>条数据</span><itcast:page url="${pageContext.request.contextPath }/adminMessage/lsotMessage" />
						</div>
             </div>
            </div>
            </div>
            
            
      </div>
      <!-- /#page-wrapper -->
   </div>
   
   
		
		<!--编辑弹出层-->
		<div class="update_modal">
		<!-- 模态框（Modal） -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content" style="background-color:#A6A6A6;">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>

						<h4 class="modal-title" id="myModalLabel">
					详情
				</h4>
					
					<form class="form-horizontal" role="form" id="messageForm" method="post">
						
						<div class="form-group">
							
							<div class="col-sm-4">
								<input type="hidden" class="form-control" id="id" name="id" value="">
							</div>
						</div>
	
						<div class="form-group">
							<label for="founder" class="col-sm-2 control-label">留言人</label>
							<div class="col-sm-4">
								<span id="founder" name="founder"></span>
							</div>
						</div>
						
						<div class="form-group">
							<label for="pname" class="col-sm-2 control-label">动物名</label>
							<div class="col-sm-4">
								<span id="pname" name="pname"></span>
							</div>
						</div>
						
						<div class="form-group">
							<label for="lmessage" class="col-sm-2 control-label">留言</label>
							<div class="col-sm-6">
								<span id="lmessage" name="lmessage" style="width: 450px; height: 250px;"></span>
							</div>
						</div>
						
						<div class="form-group">
							<label for="isshow" class="col-sm-2 control-label">禁言</label>
							<div class="col-sm-4">
								<span id="isshow" name="isshow"></span>
							</div>
						</div>
						
						<div class="form-group">
							<label for="ldate" class="col-sm-2 control-label">日期</label>
							<div class="col-sm-4">
								<span id="ldate" name="ldate"></span>
							</div>
						</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
						<button type="button" class="btn btn-primary" onclick="updateMeIsshow()">
					禁言
				</button>
				</div>
				</form>
				
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
		<!-- /.modal -->
		</div>
    <!-- /#wrapper -->

<link href="${pageContext.request.contextPath }/css/custom.css" rel="stylesheet">

<script src="${pageContext.request.contextPath }/js/metisMenu.min.js"></script>
<script src="${pageContext.request.contextPath }/js/custom.js"></script>

<script type="text/javascript">

/* 页面信息回显 */
     function showMessage(id){
    		$.post(
    			"<%=basePath%>adminMessage/showMessage",
    			{"id":id},
    			function (data) {
    				$("#id").val(data.id);
					$("#founder").html(data.founder);
					$("#pname").html(data.pname);
					$("#lmessage").html(data.lmessage);
					if(data.isshow == 1){
						$("#isshow").html("否");	
					}				
					if(data.isshow == 2){
						$("#isshow").html("是");	
					}
					$("#ldate").html(data.ldate);
					
    			},
    			"json"
    		);
    	  }
    	  
     /* 禁言*/
     function updateMeIsshow() {
    	
    	 $.post(		
			"<%=basePath%>adminMessage/updateShow",
			$("#messageForm").serialize(),
			function (data) {
				alert("已禁言!");
				location.href="<%=basePath%>adminMessage/lsotMessage";
			}
    		 );
	}
     
     /* 解除禁言 */
     function cancelsay(id) {
		$.post(
				"<%=basePath%>adminMessage/cancelsay",
				{"id":id},
				function (data) {
					alert("已解除!");
					location.href="<%=basePath%>adminMessage/lsotMessage";
				}
		);
	}
     
     
     //删除留言,单个删除
     function deleteMessage(id) {
    	 var y = confirm("您确定要删除吗?");
    	 if(y){
    		 $.post(
    					"<%=basePath%>adminMessage/delmessage",
    					{"id":id},
    					function (data) {
    						alert("删除成功");
    						location.href="<%=basePath%>adminMessage/lsotMessage";
    					}
    					);
    	 }
		
	}
     
     
</script>
</body>
</html>